<?
/*
 * Galeri, version 0.1
 * (c) 2007 Fajran Iman Rusadi.
 *
 * Galeri is freely distributable under the terms of an MIT-style license.
 *
 */


function getValidPath($path) {
	global $_images_dir;

	//get absolute path
	$base = str_replace('\\', '/', realpath('./' . $_images_dir . '/'));
	$imagePath = str_replace('\\', '/', realpath($base . $path));
//echo $imagePath;
	//check path prefix, valid if equal
	if (substr($imagePath, 0, strlen($base)) == $base) {
		return array(
			'base' => $base,
			'path' => substr($imagePath, strlen($base))
		);
	}
	else {
		return false;
	}
}

function isTitleText($filename){
    $path = $filename;
   	$file = basename($path, ".title.txt");
	$realbase = basename($path);

	return ($file == $realbase ? false : true );
}

function readCaptionImage($filename){
    $filename = $filename . '.title.txt';
    if (file_exists($filename)){
	    $content = file($filename);//fread($file, filesize($filename));
	    return trim($content[0]);
    }else{
        return "";
    }
}

function readDetailImage($filename){
    $filename = $filename . '.title.txt';
    if (file_exists($filename)){
	    $content = file($filename);//fread($file, filesize($filename));
	    return trim($content[0]);
    }else{
        return "";
    }
}
?>
